package org.spolo.android.app.topic;

import java.util.ArrayList;
import java.util.List;

import org.spolo.android.support.nodetree.Stage;
import org.spolo.android.support.nodetree.Vcanvas;

/*
 *	author:wxd 
 *	base topic
 */
public abstract class BaseTopic {
	protected Stage stage = Stage.getInstance();
	protected List<Vcanvas> list = new ArrayList<Vcanvas>();
	// 用于判断该Topic是否已经初始化过了
	protected boolean flag = false;

	/**
	 * 将该topic中的movieclip从场景树中移除
	 */
	public void Deactive() {
		for (int i = 0; i < list.size(); i++) {
			Vcanvas vc = list.get(i);
			if (stage.getM_children().contains(vc)) {
				stage.removeChild(vc);
			}
		}
		// 清空list，不缓存list
		list.clear();
		flag = false;
	}

	/**
	 * 激活该topic，将其中的movieclip添加到场景树中
	 */
	public void Active() {
		this.goInit();
		for (int i = 0; i < list.size(); i++) {
			if (!stage.getM_children().contains(list.get(i))) {
				stage.addChild(list.get(i));
			}

		}
	}

	/**
	 * 添加movieclip
	 * 
	 * @param mc
	 */
	protected void addMc(Vcanvas mc) {
		this.list.add(mc);
	}

	/**
	 * 初始化movieclip
	 */
	protected abstract void init();

	/**
	 * 获取topic中所包含的vcanvas对象
	 * 
	 * @return
	 */
	public List<Vcanvas> getList() {
		return this.list;
	}

	private void goInit() {
	}

	/**
	 * 刷新当前topic的内容
	 * 
	 * @param vc
	 *            实际上传入的是ActionParameter对象,也就是说可以强制转型为ActionParameter
	 */
	public void refreshContent(Object vc) {
	}
}
